package lib.bone.system.module.iojob.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

/**
 * @author kindear
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "io_job")
@EntityListeners(AuditingEntityListener.class)
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class IOJob {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @ApiModelProperty(value = "文件ID",name = "id")
    String id;

    @ApiModelProperty(value = "任务类型",notes = "分为导出任务和导入任务")
    @Column(name = "job_type")
    String jobType;

    @ApiModelProperty(value = "冲突处理模式",notes = "分为新建和更新模式")
    @Column(name = "job_mode")
    String jobMode;

    @ApiModelProperty(value = "任务进行状态",notes = "")
    @Column(name = "job_status")
    String jobStatus;

    @ApiModelProperty(value = "Job创建人ID",notes = "")
    @Column(name = "creater_id")
    String createrId;

    @ApiModelProperty("Job创建人")
    @Column(name = "creater")
    String creater;

    /**
     * 文件名称
     */
    @ApiModelProperty(value = "文件名称",notes = "")
    @Column(name = "file_name")
    String fileName;

    /**
     * 文件路径 key 用于下载
     */
    @ApiModelProperty(value = "文件路径",notes = "")
    @Column(name = "file_path",length = 256)
    String filePath;

    @ApiModelProperty(value = "日志文件路径",notes = "")
    @Column(name = "log_file_path")
    String logFilePath;

    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;

    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        IOJob ioJob = (IOJob) o;
        return id != null && Objects.equals(id, ioJob.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
